// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 存放轮播图数据的列表
    swiperList: [],
    
    // 存放九宫格数据的列表
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ], iconStyle: [
      {
        "type":"success",
        "size":30,
        "color":"#32CD32"
      },
      {
        "type": "success_no_circle",
        "size": 30,
        "color": "orange"
      },
      {
        "type": "info",
        "size": 30,
        "color": "yellow"
      },
      {
        "type": "warn",
        "size": 30,
        "color": "green"
      },
      {
        "type": "waiting",
        "size": 30,
        "color": "rgb(0,255,255)"
      },
      {
        "type": "cancel",
        "size": 30,
        "color": "blue"
      },
      {
        "type": "download",
        "size": 30,
        "color": "purple"
      },
      {
        "type": "search",
        "size": 30,
        "color": "#C4C4C4"
      },
      {
        "type": "clear",
        "size": 30,
        "color": "red"
      }],
    // 存放九宫格数据的列表
    gridList: [],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    src:["http://m.qpic.cn/psc?/V52c42rt2vCUKY1Xc95O0WAvBl2WBTnR/ruAMsa53pVQWN7FLK88i5p8Q77c8uX1xdqeEGp66kO6AUC.qFrRzuX5ALaC74tx6o3Yjl2CKHofUPfBP9VI8TxEivwAzRFwToeU4PZiehLU!/b&bo=VQhABgASgA0BCao!&rf=viewer_4",
  "http://a1.qpic.cn/psc?/V52c42rt2vCUKY1Xc95O0WAvBl2WBTnR/ruAMsa53pVQWN7FLK88i5g69jKkHtvXAiyp.iqLX7K2Ix2lUapOOzX2bf6yPgAnEmcXZ5eNmSW4I.WrxbbIkdUMp8CubNR*RghCLFHNeY0o!/b&ek=1&kp=1&pt=0&bo=VQhABgASgA0BOZo!&tl=3&vuin=1029980084&tm=1605535200&sce=60-2-2&rf=viewer_4","http://m.qpic.cn/psc?/V52c42rt2vCUKY1Xc95O0WAvBl2WBTnR/45NBuzDIW489QBoVep5mcSEqQonkrJSUWYgC3DAJhdBCx7ThM9G.aVv1IW4lzpbOLwuYuEcYdbtIAvk4P*wuUOJWgq.zpfrbFT2wFhAjaUA!/b&bo=QAZVCIANABIBKYo!&rf=viewer_4"],
    data: [
      {
        img: " 自己写着玩的,小程序demo 明天要下雨记得收衣服",
        linkurl: "",
        linkname: "",
        starspos: 0,
        back_color: "gold"
      }, {
        img: " 自己写着玩的,小程序demo ",
      }, {
        img: "明天要下雨记得收衣服",
      }
      , {
        img: " text加selectable长按可选",
      }
    ],
    
    broadcast_arr: {
      speed: 3.8, //滚动速度，每秒2.8个字
      font_size: "16", //字体大小(px)
      text_color: "#ffffff", //字体颜色
      back_color: " #3296fa", //背景色
    }
  },

// ----------------------滚动信息栏目------



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {



    let ititdata = this.data.data,
      assist = this.data.broadcast_arr,
      this_width = 0,
      spacing = 0,
    speed = (this.data.broadcast_arr.speed * this.data.broadcast_arr.font_size); //m每秒行走的距离
    for (let i in ititdata) {
      ititdata[i].starspos = wx.getSystemInfoSync().windowWidth; //以取屏幕宽度为间距
      this_width += ititdata[i].img.length * this.data.broadcast_arr.font_size;
      if (i != ititdata.length - 1) {
        spacing += ititdata[i].starspos
      }
    }
    let total_length = this_width + spacing;//总长
    assist.time = total_length / speed; /**滚动时间*/
    assist.width_mal = total_length; 
    this.setData({
      broadcast_arr: assist,
      data: ititdata
    })


// 获取相册权限
    wx.authorize({
  scope: 'scope.writePhotosAlbum',
    complete() {
    }
})
  },

  // 获取轮播图数据的方法
  getSwiperList() {
    wx.request({
      url: 'https://www.escook.cn/slides',
      method: 'GET',
      success: (res) => {
        this.setData({
          swiperList: res.data
        })
      }
    })
  },

  // 获取九宫格数据的方法
  getGridList() {
    wx.request({
      url: 'https://www.escook.cn/categories',
      method: 'GET',
      success: (res) => {
        this.setData({
          gridList:res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    alert(5666)

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})